package com.lingjtx.common.security.strategy;

import com.lingjtx.common.core.RedisOptions;
import com.lingjtx.common.core.ResponseCode;
import com.lingjtx.common.core.ResponseResult;
import com.lingjtx.common.core.constant.Const;
import com.lingjtx.common.core.util.StringUtil;
import com.lingjtx.common.core.token.AuthToken;
import com.lingjtx.common.core.token.UserDetail;

public class AuthStrategy extends TokenStateHandler {
    @Override
    public ResponseResult<Object> retError() {
        return ResponseResult.createByError(ResponseCode.NOT_CERTIFIED);
    }

    @Override
    public boolean handler(RedisOptions redis, String token) {
        if (StringUtil.isNotEmpty(token) && redis.exists(token)) {
            UserDetail user = AuthToken.getUser(token);
            if (user != null) {
                return Const.AuthenticationStatus.CERTIFIED == user.getCertificationStatus();
            }
        }
        return false;
    }
}
